package cn.edu.zut.controller;

import cn.edu.zut.domain.Notice;
import cn.edu.zut.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService service;

    @RequestMapping("/findAll.do")
    public @ResponseBody List<Notice> findAll() {
        return service.findAll();
    }

    @RequestMapping("/add.do")
    public @ResponseBody void add(String title,String content,String time,String receiver){
        int _id=service.findEmptyNoticeId();//找一个通知表中没有的_id
        Notice notice=new Notice(_id, title, content, time, receiver);
        service.add(notice);
    }

    @RequestMapping("/update.do")
    public @ResponseBody void update(int _id, String title,String content,String time,String receiver){
        Notice notice=new Notice( _id, title, content, time, receiver);
        service.update(notice);
    }

    @RequestMapping("/delete.do")
    public @ResponseBody void deleteById(int _id){ service.deleteById(_id); }

    @RequestMapping("/findByNoticeId.do")
    public @ResponseBody Notice findByNoticeId(int _id){ return service.findByNoticeId(_id); }

    @RequestMapping("/findByTitle.do")
    public  @ResponseBody List<Notice> findByTitle(String title){ return service.findByTitle(title); }
}
